<template>
  <div>
    <div class="titler">情报信息<span>{{ current }}</span></div>
    <div style="margin: 20px 0">

      <a-button @click="followExcelXlsFun">导出</a-button>
    </div>
    <custom-table
      ref="table"
      rowKey="id"
      :showColSettings="false"
      :hideColSettings="['action']"
      :showAlert="false"
      :showSelection="true"
      :loading="loading"
      :columns="columns"
      :dataSource="pageData"
      @selectedRow="onSelectedRow"
      @change="onTableChange"
    >
      <template slot="leaveIntoIslandType" slot-scope="text, record">
        <span v-if="text === 1">出岛</span>
        <span v-if="text === 2">入岛</span>

      </template>
      <template slot="leaveIntoIslandWay" slot-scope="text, record">
        <span v-if="text === 1">飞机</span>
        <span v-if="text === 2">火车</span>
        <span v-if="text === 3">轮船</span>
        <span v-if="text === 4">公汽</span>
        <span v-if="text === 5">自驾车</span>

      </template>
    </custom-table>
  </div>

</template>

<script>
import CustomTable from '@/components/zxd/Table/CustomTable'
import {followExcelXls, getInformation} from "@api/wxSmuggle/intelligence";
export default {
  name: "mingwenXQList",
  components:{
    CustomTable
  },
  data(){
    return {
      selectRows:[],
      pageFilter: {
        pageNo: 1,
        pageSize: 10,
      },
      loading:false,
      pageData:{},
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          scopedSlots: { customRender: 'order' },
          align: 'center',
          width: 60,
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
        },
        {
          title: '始发地',
          dataIndex: 'startDeparturePosition',
          align: 'center',
          scopedSlots: { customRender: 'startDeparturePosition' }
        },
        {
          title: '目的地',
          dataIndex: 'destination',
          align: 'center',
          scopedSlots: { customRender: 'destination' }
        },
        {
          title: '出入岛类型',
          dataIndex: 'leaveIntoIslandType',
          align: 'center',
          scopedSlots: { customRender: 'leaveIntoIslandType' }
        },
        {
          title: '出入岛方式',
          dataIndex: 'leaveIntoIslandWay',
          align: 'center',
          scopedSlots: { customRender: 'leaveIntoIslandWay' }
        },
        {
          title: '出入岛班次',
          dataIndex: 'leaveIntoIslandClasses',
          align: 'center',
          scopedSlots: { customRender: 'leaveIntoIslandClasses' }
        },
        {
          title: '出入岛班次时间',
          dataIndex: 'leaveIntoIslandTime',
          align: 'center',
          scopedSlots: { customRender: 'leaveIntoIslandTime' }
        },
        {
          title: '情报推送时间',
          dataIndex: 'intelligencePushTime',
          width: 140,
          align: 'center',
          scopedSlots: { customRender: 'leaveIntoIslandTime' }
        },
        // {
        //   title: '操作',
        //   width: 100,
        //   align: 'center',
        //   dataIndex: 'action',
        //   // slots: { title: 'customIsAction' },
        //   scopedSlots: { customRender: 'action' }
        // }
      ],
      record:{},
      current:undefined
    }
  },
  watch: {
    $route: { // 监听路由的参数变化
      handler () { // 数据变化更新数据
        this.record = this.$route.query.records
        this.refreshTable()
      },
      immediate: true // 立即执行
    }
  },
  mounted() {
    this.record = this.$route.query.records
    this.refreshTable()
    console.log(this.$route.query)
    console.log(this.record)
  },
  methods:{
    followExcelXlsFun(){
      console.log(this.selectRows)
      followExcelXls({id:this.selectRows}).then(ser => {

      })
    },

    refreshTable(){
      getInformation({id:this.record}).then(ser => {
        console.log(ser)
        this.current = ser.total
        this.pageData = ser.records
      })
    },
    onSelectedRow(rows,key) {
      console.log('rows')
      console.log(rows)
      this.selectRows = key
      // this.isDisabled = rows.length > 0 ? false : true
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'pageNo' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      // this.refreshTable()
    },
  }
}
</script>

<style scoped>
.titler{
  font-size: 20px;
  font-weight: 600;
}
</style>